package com.saleoffline.server.domain.sale;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import com.saleoffline.server.domain.SqlMapDAO;

import org.springframework.stereotype.Repository;

@Repository
public class SaleDAO extends SqlMapDAO {
	public static final String NAMESPACE = "Sale";

	public int insert(Sale sale) {
		Integer id = (Integer)getSqlMapClientTemplate().insert(getStatementName(NAMESPACE, "insert"), sale);
		return id;
	}

	public int update(Sale sale) {
		return getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "update"), sale);
	}
	
	public int delete(int id) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		return getSqlMapClientTemplate().delete(getStatementName(NAMESPACE, "delete"), params);	
	}
	
	public Sale select(int id) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		return (Sale)getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "select"), params);
	}

	@SuppressWarnings("unchecked")
	public List<Sale> search(SaleSearch search) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "search"), search);
	}
}